﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;

namespace WebDavTest
{
    /// <summary>
    /// Summary description for Directory
    /// </summary>
    [TestClass]
    public class Directory
    {
        public Directory()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext) { Reset.ResetRepository(); }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void CreateDirectory()
        {
            List<WebDav.WebDav.Entity> lstEntities;
            WebDav.WebDav webdav = new WebDav.WebDav(null, null);
            HttpStatusCode status = new HttpStatusCode();

            webdav.CreateDirectory(Reset.UnitsTestRepository + "CreateDirectoryTest", ref status);
            lstEntities = webdav.BrowseDirectory(Reset.UnitsTestRepository + "CreateDirectoryTest");

            Assert.IsNotNull(lstEntities);
            Assert.AreEqual(lstEntities.Count, 1);
        }

        /// <summary>
        /// Thi Unit test doesnot work becausz the current server webdav doesnot support delete method
        /// </summary>
        [TestMethod]
        public void RemoveDirectory()
        {
            List<WebDav.WebDav.Entity> lstEntities;
            WebDav.WebDav webdav = new WebDav.WebDav(null, null);
            HttpStatusCode status = new HttpStatusCode();

            webdav.Delete(Reset.UnitsTestRepository + "test", ref status);

            lstEntities = webdav.BrowseDirectory(Reset.UnitsTestRepository + "test");

            Assert.IsNull(lstEntities);
            //Assert.AreEqual(lstEntities.Count, 0);
        }
    }
}
